/*
**通用日志创造器
*/

#pragma once

#include "abstract_loger.hpp"
#include "log_fmter.hpp"

namespace lxz
{

    class loger
    {
    public:
        loger(const loger &that) = delete;
        loger &operator=(const loger &that) = delete;

        loger(const loger &&that) = delete;
        loger &operator=(const loger &&that) = delete;

        ~loger();

        static loger *getInstance(void);

        int32_t init(log_level level = log_level::LOG_LEVEL_DEBUG, log_type type = log_type::LOG_TYPE_STDOUT, const char *file = nullptr);

        int32_t append(log_level level, const std::string &log);

    private:
        abstract_loger *loger_; // 多态指针

        loger();
    };

} // namespace lxz

#ifdef NDEBUG
#define LOG_DEBUG(fmt, ...) \
    do                      \
    {                       \
        ;                   \
    } while (0);
#else
#define LOG_DEBUG(fmt, ...) lxz::loger::getInstance()->append(lxz::LOG_LEVEL_DEBUG, lxz::log_fmter::work(lxz::LOG_LEVEL_DEBUG, __FILE__, __FUNCTION__, __LINE__, (const char *)fmt, ##__VA_ARGS__))
#endif

#define LOG_INFO(fmt, ...) lxz::loger::getInstance()->append(lxz::LOG_LEVEL_INFO, lxz::log_fmter::work(lxz::LOG_LEVEL_INFO, __FILE__, __FUNCTION__, __LINE__, (const char *)fmt, ##__VA_ARGS__))
#define LOG_WARN(fmt, ...) lxz::loger::getInstance()->append(lxz::LOG_LEVEL_WARN, lxz::log_fmter::work(lxz::LOG_LEVEL_WARN, __FILE__, __FUNCTION__, __LINE__, (const char *)fmt, ##__VA_ARGS__))
#define LOG_ERR(fmt, ...) lxz::loger::getInstance()->append(lxz::LOG_LEVEL_ERR, lxz::log_fmter::work(lxz::LOG_LEVEL_ERR, __FILE__, __FUNCTION__, __LINE__, (const char *)fmt, ##__VA_ARGS__))
